package com.kede.api.utils;

import com.kede.api.ienum.EnvEnum;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author:Pr.li
 * @Date: create in 2023/9/2 13:56
 */
@Component
public class SpringUtil implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }
    public static EnvEnum getEnv(){
        String[] activeProfiles = applicationContext.getEnvironment().getActiveProfiles();
        for (String activeProfile : activeProfiles) {
            switch (activeProfile){
                case "prod":
                    return EnvEnum.PROD;
                case "test":
                    return EnvEnum.TEST;
            }
        }
        return EnvEnum.DEV;
    }

}
